package com.study.spmongodb.wwj.thread2.char17;

import java.util.Random;

/**
 * @author study
 * @version 1.0
 * @date 2020/12/9 15:10
 */
public class WorkThread extends Thread {

    private final static Random random = new Random(System.currentTimeMillis());
    private final Channel channel;

    public WorkThread(String name, Channel channel) {
        super(name);
        this.channel = channel;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(random.nextInt(1_000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            channel.take().execute();
        }
    }
}
